Introduction to NumPy

Final exercise

The final data in the data file is information about wind velocity, specifically "wind_u" which is the wind speed in $ms^{-1}$ towards the East and "wind_v" which is the same towards the North.

with np.load("weather_data.npz") as weather:
    wind_u = weather["wind_u"]
    wind_v = weather["wind_v"]
    temperature = weather["temperature"]
    rain = weather["rain"]

    uk_mask = weather["uk"]
    irl_mask = weather["ireland"]
    spain_mask = weather["spain"]
  • Plot the U and the V components of the wind (think about an appropriate colour map and any useful arguments from plt.imshow)
  • Calculate the total wind speed, which is given by $s = \sqrt{u^2+v^2}$
  • Calculate the direction of the wind, which is given by $\theta = \mathrm{arctan2}(u, v)$
    • you will need to find the appropriate function in the NumPy docs
  • Plot the two new arrays. Consider approprate colour maps for them too.

Using these arrays, calculate the following:

  • the average wind direction and speed in the UK?
  • the average wind direction and speed in Spain?

answer